<?php
class List_pinjam extends CI_Controller {

	function __construct()
	{
		parent::__construct();	
		$this->load->helper('flexigrid');
		$this->load->helper('format');
		$this->load->library('flexigrid');
		$this->load->library('form_validation');
		$this->load->model('siswa_model');
		$this->load->model('guru_model');
		$this->load->model('perpus/refrensi_model');
		$this->load->model('perpus/transaksi_model');
		$this->load->model('perpus/pustaka_model');
	}
	
	function index($act='')
	{
		$data['value_nisn'] = '';
		$data['value_jenisanggota'] = '';
		$data['value_namaanggota'] = '';
		if($act == 'act_filter'){
			$data['value_nisn'] = $this->input->post('nisn');
			$data['value_jenisanggota'] = $this->input->post('h_jenisanggota');
			$data['value_namaanggota'] = $this->input->post('nama_anggota');
			$this->session->set_userdata('sess_nisn', $this->input->post('nisn'));
			$this->session->set_userdata('sess_jenisanggota', $this->input->post('h_jenisanggota'));
			$this->session->set_userdata('sess_namaanggota', $this->input->post('nama_anggota'));
		}else{
			$data['value_nisn'] = $this->session->userdata('sess_nisn');
			$data['value_jenisanggota'] = $this->session->userdata('sess_jenisanggota');
			$data['value_namaanggota'] = $this->session->userdata('sess_namaanggota');
		}
		
		/*
		 * 0 - display name
		 * 1 - width
		 * 2 - sortable
		 * 3 - align
		 * 4 - searchable (2 -> yes and default, 1 -> yes, 0 -> no.)
		 */
		$colModel['no'] = array('No',40,TRUE,'center',0);
		if($this->session->userdata('roleid')=='0'){ //diknas
			$colModel['NAMA_SEKOLAH'] = array('Nama Sekolah',100,TRUE,'center',1);
		}
		$colModel['KODE_EKSEMPLAR'] = array('Kode Eksemplar',100,TRUE,'center',1);
		$colModel['JUDUL'] = array('Judul',200,TRUE,'center',1);
		$colModel['TGL_PINJAM'] = array('Tgl. Pinjam',100,TRUE,'center',1);
		$colModel['TGL_TENGGAT'] = array('Tgl. Tenggat',100,TRUE,'center',1);
		$colModel['TELAT'] = array('Terlambat (Hari)',100,TRUE,'center',0);
		$colModel['DENDA'] = array('Denda',100,TRUE,'center',0);
		$colModel['ubah'] = array('Aksi',50,FALSE,'center',0);
		
		/*
		 * Aditional Parameters
		 */
		$gridParams = array(
		'width' => 'auto',
		'height' => '300',
		'rp' => 10,
		'rpOptions' => '[10,15,20,25,40]',
		'pagestat' => 'Displaying: {from} to {to} of {total} items.',
		'blockOpacity' => 0.5,
		'title' => 'Daftar Peminjaman'
		);
		
		/*
		 * 0 - display name
		 * 1 - bclass
		 * 2 - onpress
		 */
		if(!empty($data['value_nisn']))
		$buttons[] = array('Tambah Transaksi','add','org_js');
		// $buttons[] = array('Delete','delete','org_js');
		$buttons[] = array('separator');
		// $buttons[] = array('Select All','add','org_js');
		// $buttons[] = array('Deselect All','delete','org_js');
		// $buttons[] = array('separator');
		
		//Build js
		//View helpers/flexigrid_helper.php for more information about the params on this function
		$grid_js = build_grid_js('flex1',site_url("perpus/list_pinjam/listpinjam_grid/".$data['value_nisn']."/".$data['value_jenisanggota']),$colModel,'no','asc',$gridParams,$buttons);
		
		if($this->session->flashdata('suc_msg'))
			$data['header_info'] = '<div class="ret_success">'.$this->session->flashdata('suc_msg').'</div>';
		
		$data['title'] = "Contoh Flexigrid";
		$data['info'] = "Flexigrid";
		$data['js_grid'] = $grid_js;
		$data['version'] = "0.36";
		$data['download_file'] = "Flexigrid_CI_v0.36.rar";
		
		$data['added_js'] = 
			"<script type='text/javascript'>
			function org_js(com,grid)
			{
				if (com=='Select All')
				{
					$('.bDiv tbody tr',grid).addClass('trSelected');
				}
				
				if (com=='Deselect All')
				{
					$('.bDiv tbody tr',grid).removeClass('trSelected');
				}
				
				if (com=='Tambah Transaksi')
				{
					location.href='".base_url()."index.php/perpus/list_pinjam/peminjaman/'; 
					// win = window.open('".base_url()."index.php/perpus/list_pinjam/peminjaman','popup_transaksi','width=400,height=200,scrollbars=0');
					// win.focus();
				}
				
				if (com=='Delete')
				{
				   if($('.trSelected',grid).length>0){
					   if(confirm('Anda yakin ingin menghapus ' + $('.trSelected',grid).length + ' buah data?')){
							var items = $('.trSelected',grid);
							var itemlist ='';
							for(i=0;i<items.length;i++){
								itemlist+= items[i].id.substr(3)+',';
							}
							$.ajax({
							   type: 'POST',
							   url: '".site_url('/perpus/list_pinjam/delete_pinjam')."',
							   data: 'items='+itemlist,
							   success: function(data){
								$('#flex1').flexReload();
								alert(data);
							   }
							});
						}
					} else {
						return false;
					} 
				}          
			} 
			
			function goKembali(id,jmldenda){
				var kembali=confirm('Apakah Anda yakin akan mengembalikan buku ini?');
				if (kembali){
					location.href='".base_url()."index.php/perpus/list_pinjam/pengembalian/'+id+'/'+jmldenda; 
				}
			}
			</script>
			";	
		$data['filter_nisn'] = 'isi';
		$data['width'] = '700';
		$data['url_filter'] = 'perpus/list_pinjam/index/act_filter';
		$data['content'] = $this->load->view('grid',$data,true);
		$this->load->view('main',$data);
	}
	
	function listpinjam_grid($nisn='', $jenisanggota='')
	{
		//List of all fields that can be sortable. This is Optional.
		//This prevents that a user sorts by a column that we dont want him to access, or that doesnt exist, preventing errors.
		if($this->session->userdata('roleid')=='0') //diknas
			$valid_fields = array('NAMA_SEKOLAH','KODE_KATALOG','NAMA_KATALOG','KETERANGAN');
		else	
			$valid_fields = array('KODE_EKSEMPLAR','JUDUL','TGL_PINJAM','TGL_TENGGAT');
		
		$this->flexigrid->validate_post('a.KODE_EKSEMPLAR','asc',$valid_fields);

		$records = $this->transaksi_model->get_peminjaman($nisn);
		
		$this->output->set_header($this->config->item('json_header'));
		$no = 0;
		/*
		 * Json build WITH json_encode. If you do not have this function please read
		 * http://flexigrid.eyeviewdesign.com/index.php/flexigrid/example#s3 to know how to use the alternative
		 */
		foreach ($records['records']->result() as $row)
		{
			$telat = hitungTelat($row->TGL_TENGGAT, date('Y-m-d'));
			if($row->NISN != '')
				$denda = $this->hitungDenda($telat,'1');
			if($row->NIP != '')
				$denda = $this->hitungDenda($telat,'2');
				
			if($telat>0){
				$record_items[] = array($row->ID_PINJAM,
				$no+1,
				'<div align="center"><font color="red"><blink>'.$row->KODE_EKSEMPLAR.'</blink></font></div>',
				'<div align="left"><font color="red"><blink>'.$row->JUDUL_BUKU.'</blink></font></div>',
				'<div align="left"><font color="red"><blink>'.xFormatDate($row->TGL_PINJAM).'</blink></font></div>',
				'<div align="left"><font color="red"><blink>'.xFormatDate($row->TGL_TENGGAT).'</blink></font></div>',
				'<div align="left"><font color="red"><blink>'.$telat.'</blink></font></div>',
				'<div align="left"><font color="red"><blink>Rp. '.xFormatNumber($denda).',-</blink></font></div>',
				'<a title="Kembalikan Pustaka" href=\'javascript:goKembali("'.$row->ID_PINJAM.'","'.$denda.'")\'><img border=\'0\' src=\''.base_url().'images/perpustakaan/kembalikan.png\'></a> '
				// '<a title="Kembalikan Pustaka" href=\''.site_url().'/perpus/list_pinjam/pengembalian/'.$row->ID_PINJAM.'/'.$denda.'/\'><img border=\'0\' src=\''.base_url().'images/perpustakaan/kembalikan.png\'></a> '
				);
				$no++;
			}else{
				$record_items[] = array($row->ID_PINJAM,
				$no+1,
				'<div align="center">'.$row->KODE_EKSEMPLAR.'</div>',
				'<div align="left">'.$row->JUDUL_BUKU.'</div>',
				'<div align="left">'.xFormatDate($row->TGL_PINJAM).'</div>',
				'<div align="left">'.xFormatDate($row->TGL_TENGGAT).'</div>',
				'<div align="left">'.$telat.'</div>',
				'<div align="left">Rp. '.xFormatNumber($denda).',-</div>',
				'<a title="Kembalikan Pustaka" href=\'javascript:goKembali("'.$row->ID_PINJAM.'","'.$denda.'")\'><img border=\'0\' src=\''.base_url().'images/perpustakaan/kembalikan.png\'></a> '
				// '<a title="Kembalikan Pustaka" href=\''.site_url().'/perpus/list_pinjam/pengembalian/'.$row->ID_PINJAM.'/'.$denda.'/\'><img border=\'0\' src=\''.base_url().'images/perpustakaan/kembalikan.png\'></a> '
				);
				$no++;
			}
		}
		//Print please
		if(isset($record_items))
				$this->output->set_output($this->flexigrid->json_build($records['record_count'],$record_items));
			else
				$this->output->set_output('{"page":"1","total":"0","rows":[]}');
	}
	
	function hitungDenda($telat,$jenisanggota){
		$rs_cek_denda = $this->transaksi_model->getDenda($jenisanggota)->row();
		$hitung = $rs_cek_denda->DENDA * $telat;
		return $hitung;
	}

	function cek_validasi() {	
			// Setting Rules
			if($this->session->userdata('roleid')=='0') //diknas
				$this->form_validation->set_rules('nama_sekolah', 'Nama Sekolah', 'required');
			
			$this->form_validation->set_rules('kode_eksemplar', 'Kode Eksemplar', 'required|callback_cekmaxpinjam');
			
			// Setting Error Message
			$this->form_validation->set_message('required', 'Kolom %s harus diisi!!');
			
			// Setting Delimiter
			$this->form_validation->set_error_delimiters('<li class="error">', '</li>');
			return $this->form_validation->run();
	}
	
	function cekmaxpinjam(){
		$maxpinjam = $this->pustaka_model->get_konfigurasi($this->session->userdata('sess_jenisanggota'))->row()->MAX_PINJAM;
		$rs_pinjam = $this->transaksi_model->get_jmlpinjam($this->session->userdata('sess_nisn'))->row()->jmlpinjam;
		
		if($rs_pinjam<$maxpinjam){
			return TRUE;
		}else{
			$this->form_validation->set_message('cekmaxpinjam', ' Peminjaman melebihi batas maksimal.');
			return FALSE;
		}
	}
	
	function peminjaman(){
		if ($this->cek_validasi() == FALSE){
			$data = '';
			$data['content'] = $this->load->view('perpus/form_peminjaman', $data, TRUE);
			$this->load->view('main',$data);
		}else{
			$this->insert_peminjaman();
		}
	}
	
	function insert_peminjaman(){
		$konf = $this->pustaka_model->get_konfigurasi($this->session->userdata('sess_jenisanggota'))->row();
		$tgl = strtotime(date('Y-m-d')) + (86400*$konf->MAX_KEMBALI);
		$tgl_tenggat = date("Y-m-d",$tgl);
		
		if($this->session->userdata('sess_jenisanggota')=='1'){
			$nisn = $this->session->userdata('sess_nisn');
			$nip = '';
		}else{
			$nisn = '';
			$nip = $this->session->userdata('sess_nisn');
		}
		
		$data = array(
			'KODE_EKSEMPLAR'		=> $this->input->post('kode_eksemplar'),
			'TGL_PINJAM'			=> date('Y-m-d'),
			'NISN'					=> $nisn,
			'NIP'					=> $nip,
			'TGL_TENGGAT'			=> $tgl_tenggat,
			'STATUS'				=> 1,
		);
		
		$this->transaksi_model->insert_peminjaman($data);
		
		$data = array(
			'STATUS'			=> 0
		);
		$this->pustaka_model->update_eksemplar($data,$this->input->post('kode_eksemplar'));
		$this->session->set_flashdata('suc_msg', 'Data Peminjaman berhasil disimpan.');
		redirect('perpus/list_pinjam'); 
	}
	
	function pengembalian($id_pinjam,$denda){
		$tgl_tenggat = $this->transaksi_model->get_tenggat($id_pinjam)->row();
		$telat = hitungTelat($tgl_tenggat->TGL_TENGGAT, date('Y-m-d'));
		// update pinjam
		$data = array(
			'STATUS'		=> 0,
			'TGL_KEMBALI'	=> date('Y-m-d')
		);
		$this->transaksi_model->update_peminjaman($data,$id_pinjam);
		
		//update eksemplar
		$data = array(
			'STATUS' => 1,
		);
		$this->pustaka_model->update_eksemplar($data,$tgl_tenggat->KODE_EKSEMPLAR);
		
		if($telat>0){
			//insert denda
			$data = array(
				'ID_SEKOLAH' 	=> $this->session->userdata('unitid'),
				'ID_PINJAM' 	=> $id_pinjam,
				'TELAT' 		=> $telat,
				'DENDA' 		=> $denda,
			);
			$this->transaksi_model->insert_denda($data);
		}
		$this->session->set_flashdata('suc_msg', 'Pengembalian berhasil.');
		redirect('perpus/list_pinjam'); 
	}
	
	//Delete
	function delete_katalog()
	{
		$ta_ids_post_array = explode(",",$this->input->post('items'));
		$msg = '';
		foreach($ta_ids_post_array as $index => $ta_id){
			if (isset($ta_id) && $ta_id != "") {
				$this->refrensi_model->delete_katalog($ta_id);
						
			
			$msg .= "Data Katalog Pustaka berhasil dihapus.\n";
			}
		}
		$this->output->set_header($this->config->item('ajax_header'));
		$this->output->set_output($msg);
	}
	
	function list_siswa()
	{
		
		/*
		 * 0 - display name
		 * 1 - width
		 * 2 - sortable
		 * 3 - align
		 * 4 - searchable (2 -> yes and default, 1 -> yes, 0 -> no.)
		 */
		$colModel['no'] = array('No',40,TRUE,'center',0);
		$colModel['NISN'] = array('NIS',100,TRUE,'center',1);
		$colModel['NAMA_LENGKAP'] = array('Nama lengkap',200,TRUE,'center',1);
		$colModel['Aksi'] = array('Aksi',100,TRUE,'center',0);
		
		/*
		 * Aditional Parameters
		 */
		$gridParams = array(
		'width' => 'auto',
		'height' => '345',
		'rp' => 10,
		'rpOptions' => '[10,15,20,25,40]',
		'pagestat' => 'Displaying: {from} to {to} of {total} items.',
		'blockOpacity' => 0.5,
		'title' => 'Daftar Siswa'
		);
		
		/*
		 * 0 - display name
		 * 1 - bclass
		 * 2 - onpress
		 */
		$buttons[] = array('separator');
		
		//Build js
		//View helpers/flexigrid_helper.php for more information about the params on this function
		$grid_js = build_grid_js('flex1',site_url("perpus/list_pinjam/listsiswa_grid/"),$colModel,'no','asc',$gridParams,$buttons);
		
		if($this->session->flashdata('suc_msg'))
			$data['header_info'] = '<div class="ret_success">'.$this->session->flashdata('suc_msg').'</div>';
		
		$data['title'] = "Contoh Flexigrid";
		$data['info'] = "Flexigrid";
		$data['js_grid'] = $grid_js;
		$data['version'] = "0.36";
		$data['download_file'] = "Flexigrid_CI_v0.36.rar";
		
		$data['added_js'] = 
			"<script type='text/javascript'>
			 function goSend(key1, key2, key3){
				window.opener.document.getElementById('nisn').value = key1;
				window.opener.document.getElementById('h_nisn').value = key1;
				window.opener.document.getElementById('nama_anggota').value = key2;
				window.opener.document.getElementById('h_jenisanggota').value = key3;
				window.close();
			}
			</script>
			";	
		
		$data['content'] = $this->load->view('grid',$data,true);
		$data['title'] = 'Popup Pilih Anggota Perpustakaan';
		$this->load->view('perpus/popup_list',$data);
	}
	
	function listsiswa_grid()
	{
		//List of all fields that can be sortable. This is Optional.
		//This prevents that a user sorts by a column that we dont want him to access, or that doesnt exist, preventing errors.
		$valid_fields = array('NISN','NAMA_LENGKAP');
		
		$this->flexigrid->validate_post('NISN','asc',$valid_fields);

		$records = $this->siswa_model->get_siswa();
		
		$this->output->set_header($this->config->item('json_header'));
		$no = 0;
		/*
		 * Json build WITH json_encode. If you do not have this function please read
		 * http://flexigrid.eyeviewdesign.com/index.php/flexigrid/example#s3 to know how to use the alternative
		 */
		foreach ($records['records']->result() as $row)
		{			
			$record_items[] = array($row->NISN,
			$no+1,
			'<div align="center">'.$row->NISN.'</div>',
			'<div align="left">'.$row->NAMA_LENGKAP.'</div>',
			'<a title="pilih" href=\'javascript:goSend("'.$row->NISN.'","'.$row->NAMA_LENGKAP.'","1")\'><img border=\'0\' src=\''.base_url().'images/main/28.png\'></a> '
			);
			$no++;
		}
		//Print please
		if(isset($record_items))
				$this->output->set_output($this->flexigrid->json_build($records['record_count'],$record_items));
			else
				$this->output->set_output('{"page":"1","total":"0","rows":[]}');
	}
	
	function list_pegawai_guru($jns='')
	{
		
		/*
		 * 0 - display name
		 * 1 - width
		 * 2 - sortable
		 * 3 - align
		 * 4 - searchable (2 -> yes and default, 1 -> yes, 0 -> no.)
		 */
		$colModel['no'] = array('No',40,TRUE,'center',0);
		$colModel['NIP'] = array('NIS',100,TRUE,'center',1);
		$colModel['NAMA_LENGKAP'] = array('Nama lengkap',200,TRUE,'center',1);
		$colModel['Aksi'] = array('Aksi',100,TRUE,'center',0);
		
		/*
		 * Aditional Parameters
		 */
		$gridParams = array(
		'width' => 'auto',
		'height' => '345',
		'rp' => 10,
		'rpOptions' => '[10,15,20,25,40]',
		'pagestat' => 'Displaying: {from} to {to} of {total} items.',
		'blockOpacity' => 0.5,
		'title' => 'Daftar Pegawai dan Guru'
		);
		
		/*
		 * 0 - display name
		 * 1 - bclass
		 * 2 - onpress
		 */
		$buttons[] = array('separator');
		
		//Build js
		//View helpers/flexigrid_helper.php for more information about the params on this function
		$grid_js = build_grid_js('flex1',site_url("perpus/list_pinjam/listpegawai_grid/".$jns),$colModel,'no','asc',$gridParams,$buttons);
		
		if($this->session->flashdata('suc_msg'))
			$data['header_info'] = '<div class="ret_success">'.$this->session->flashdata('suc_msg').'</div>';
		
		$data['title'] = "Contoh Flexigrid";
		$data['info'] = "Flexigrid";
		$data['js_grid'] = $grid_js;
		$data['version'] = "0.36";
		$data['download_file'] = "Flexigrid_CI_v0.36.rar";
		
		$data['added_js'] = 
			"<script type='text/javascript'>
			 function goSend(key1, key2, key3){
				window.opener.document.getElementById('nisn').value = key1;
				window.opener.document.getElementById('h_nisn').value = key1;
				window.opener.document.getElementById('nama_anggota').value = key2;
				window.opener.document.getElementById('h_jenisanggota').value = key3;
				window.close();
			}
			</script>
			";	
		
		$data['content'] = $this->load->view('grid',$data,true);
		$data['title'] = 'Popup Pilih Anggota Perpustakaan';
		$this->load->view('perpus/popup_list',$data);
	}
	
	function listpegawai_grid($jns)
	{
		//List of all fields that can be sortable. This is Optional.
		//This prevents that a user sorts by a column that we dont want him to access, or that doesnt exist, preventing errors.
		$valid_fields = array('NIP','NAMA_LENGKAP');
		
		$this->flexigrid->validate_post('NIP','asc',$valid_fields);

		$records = $this->guru_model->get_pegawai_guru($jns);
		
		$this->output->set_header($this->config->item('json_header'));
		$no = 0;
		/*
		 * Json build WITH json_encode. If you do not have this function please read
		 * http://flexigrid.eyeviewdesign.com/index.php/flexigrid/example#s3 to know how to use the alternative
		 */
		foreach ($records['records']->result() as $row)
		{		
			$gelard = ''; $gelarb = '';
			if($row->GELAR_DEPAN != '')
				$gelard = $row->GELAR_DEPAN.'. ';
			if($row->GELAR_BELAKANG != '')
				$gelarb = ', '.$row->GELAR_BELAKANG;
				
			$record_items[] = array($row->NIP,
			$no+1,
			'<div align="center">'.$row->NIP.'</div>',
			'<div align="left">'.$gelard.$row->NAMA_LENGKAP .$gelarb .'</div>',
			'<a title="pilih" href=\'javascript:goSend("'.$row->NIP.'","'.$gelard.$row->NAMA_LENGKAP .$gelarb.'","2")\'><img border=\'0\' src=\''.base_url().'images/main/28.png\'></a> '
			);
			$no++;
		}
		//Print please
		if(isset($record_items))
				$this->output->set_output($this->flexigrid->json_build($records['record_count'],$record_items));
			else
				$this->output->set_output('{"page":"1","total":"0","rows":[]}');
	}
	
	function list_eksemplar()
	{
		
		/*
		 * 0 - display name
		 * 1 - width
		 * 2 - sortable
		 * 3 - align
		 * 4 - searchable (2 -> yes and default, 1 -> yes, 0 -> no.)
		 */
		$colModel['no'] = array('No.',30,TRUE,'center',0);
		$colModel['KODE_EKSEMPLAR'] = array('Kode Eksemplar',100,TRUE,'center',1);
		$colModel['JUDUL_BUKU'] = array('Judul Buku',250,TRUE,'center',1);
		$colModel['NAMA_PENULIS'] = array('Pengarang',150,TRUE,'center',1);
		$colModel['STATUS'] = array('Status',100,TRUE,'center',0);
		
		/*
		 * Aditional Parameters
		 */
		$gridParams = array(
		'width' => 'auto',
		'height' => '345',
		'rp' => 10,
		'rpOptions' => '[10,15,20,25,40]',
		'pagestat' => 'Displaying: {from} to {to} of {total} items.',
		'blockOpacity' => 0.5,
		'title' => 'Daftar Eksemplar'
		);
		
		/*
		 * 0 - display name
		 * 1 - bclass
		 * 2 - onpress
		 */
		$buttons[] = array('separator');
		
		//Build js
		//View helpers/flexigrid_helper.php for more information about the params on this function
		$grid_js = build_grid_js('flex1',site_url("perpus/list_pinjam/listeksemplar_grid/"),$colModel,'no','asc',$gridParams,$buttons);
		
		if($this->session->flashdata('suc_msg'))
			$data['header_info'] = '<div class="ret_success">'.$this->session->flashdata('suc_msg').'</div>';
		
		$data['title'] = "Contoh Flexigrid";
		$data['info'] = "Flexigrid";
		$data['js_grid'] = $grid_js;
		$data['version'] = "0.36";
		$data['download_file'] = "Flexigrid_CI_v0.36.rar";
		
		$data['added_js'] = 
			"<script type='text/javascript'>
			 function goSend(key1){
				window.opener.document.getElementById('kode_eksemplar').value = key1;
				window.close();
			}
			</script>
			";	
		
		$data['content'] = $this->load->view('grid',$data,true);
		$data['title'] = 'Popup Pilih Kode Eksemplar';
		$this->load->view('perpus/popup_list',$data);
	}
	
	function listeksemplar_grid()
	{
		//List of all fields that can be sortable. This is Optional.
		//This prevents that a user sorts by a column that we dont want him to access, or that doesnt exist, preventing errors.
		$valid_fields = array('KODE_EKSEMPLAR','JUDUL_BUKU','NAMA_PENULIS');
		
		$this->flexigrid->validate_post('ID_EKSEMPLAR','asc',$valid_fields);

		$records = $this->pustaka_model->get_eksemplar('ada');
		
		$this->output->set_header($this->config->item('json_header'));
		$no = 0;
		/*
		 * Json build WITH json_encode. If you do not have this function please read
		 * http://flexigrid.eyeviewdesign.com/index.php/flexigrid/example#s3 to know how to use the alternative
		 */
		foreach ($records['records']->result() as $row)
		{
			if($row->STATUS == 1)
				$status_eks = 'ADA';
			
			$record_items[] = array($row->ID_EKSEMPLAR,
			$no+1,
			'<div align="left"><a title="Pilih Kode Eksemplar" href=\'javascript:goSend("'.$row->KODE_EKSEMPLAR .'")\'>'.$row->KODE_EKSEMPLAR.'</a></div>',
			'<div align="left">'.$row->JUDUL_BUKU.'</div>',
			'<div align="left">'.$row->NAMA_PENULIS.'</div>',
			'<div align="left">'.$status_eks.'</div>'
			);
			$no++;
		}
		//Print please
		if(isset($record_items))
				$this->output->set_output($this->flexigrid->json_build($records['record_count'],$record_items));
			else
				$this->output->set_output('{"page":"1","total":"0","rows":[]}');
	}
    
}
?>
